<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/comm :: head "></head>
<body>
<div class="wrapper">
    <header th:replace="common/comm :: header "></header>
    <div class="main-panel">
        <div class="content">
            <div class="container-fluid">
                <h4 class="page-title">
                    <font id="WOW_TRANSLATE_43" class="WOW_TRANSLATE_STYLE"
                          data--w-o-w_-i-n-d-e-x="43" th:if="${i==0}">培训管理 >> 修改培训计划</font>
                    <font id="WOW_TRANSLATE_43" class="WOW_TRANSLATE_STYLE"
                          data--w-o-w_-i-n-d-e-x="43" th:if="${i==1}">培训管理 >> 审核培训计划</font>
                </h4>
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-body">
                                <form class="form-inline" th:action="@{/sys/train/updateSave}" th:method="post"
                                      enctype="multipart/form-data">
                                    <input type="hidden" name="id" th:value="${train.id}">
                                    <input type="hidden" name="auditStatus" value="">
                                    <div class="form-group">
                                        <label for="code"><font>培训名称:&nbsp;&nbsp; </font></label>
                                        <input type="text" class="form-control" id="title" name="title" th:value="${train.title}">
                                        <small class="form-text text-muted"></small>
                                    </div>
                                    <div class="form-group">
                                        <label for="code"><font> 培训讲师:&nbsp;&nbsp; </font></label>
                                        <input type="text" class="form-control" id="lecturer" name="lecturer" th:value="${train.lecturer}">
                                        <small class="form-text text-muted"></small>
                                    </div>
                                    <div class="form-group">
                                        <label for="code"><font> 建档日期:&nbsp;&nbsp; </font></label>
                                        <input type="date" class="form-control" id="startDate" name="startDate"
                                               th:value="${train.startDate}">
                                        <label for="code"><font> 至:&nbsp;&nbsp; </font></label>
                                        <input type="date" class="form-control" id="endDate" name="endDate" th:value="${train.endDate}">
                                        <small class="form-text text-muted"></small>
                                    </div>
                                    <div class="form-group">
                                        <label for="testrange"> 培训目的:&nbsp;&nbsp; </label>
                                        <textarea class="form-control" rows="5" cols="105" name="goal" th:text="${train.goal}"></textarea>
                                        <small class="form-text text-muted"></small>
                                    </div>
                                    <div class="form-group">
                                        <label for="testrange"> 参训人员:&nbsp;&nbsp; </label>
                                        <textarea class="form-control" rows="5" cols="105" name="personnel" th:text="${train.personnel}"></textarea>
                                        <small class="form-text text-muted"></small>
                                    </div>
                                    <div class="form-group">
                                        <label for="testrange"> 培训简介:&nbsp;&nbsp; </label>
                                        <textarea class="form-control" rows="5" cols="105" name="intro" th:text="${train.intro}"></textarea>
                                        <small class="form-text text-muted"></small>
                                    </div>
                                    <div class="form-group" th:if="${train.trainData!=null}">
                                        <div id="trainFile" style="display: none">
                                            <label for="code"><font> 培训资料:&nbsp;&nbsp; </font></label>
                                            <input type="file"
                                                   class="form-control"
                                                   name="attach"
                                                   value="">
                                            <small class="form-text text-muted"></small>
                                        </div>
                                        <div id="trainShow">
                                            <label for="code"><font> 培训资料:&nbsp;&nbsp; </font></label>
                                            <a href="javascript:;" th:onclick="|downloadFile(${train.id})|"
                                               th:text="${train.fileName}"></a>&nbsp;&nbsp;
                                            <a href="javascript:;" th:onclick="|delFile(${train.id})|">删除</a>
                                        </div>
                                    </div>

                                    <div th:if="${train.trainData==null}">
                                        <div>
                                            <label for="code"><font>培训资料:&nbsp;&nbsp; </font></label>
                                            <input type="file" class="form-control" name="attach">
                                            <small class="form-text text-muted"></small>
                                        </div>
                                    </div>

                                    <div class="form-group" th:if="${i==1}">
                                        <label for="testrange"> 审核意见:&nbsp;&nbsp; </label>
                                        <textarea class="form-control" rows="5" cols="105" name="auditOpinion" th:text="${train.auditOpinion}"></textarea>
                                        <small class="form-text text-muted"></small>
                                    </div>


                                    <div class="form-group" style="text-align: center;" th:if="${i==0}">
                                        <input type="submit" class="btn btn-success" value="保存">
                                    </div>
                                    <div class="form-group" style="text-align: center;" th:if="${i==1}">
                                        <input type="submit" class="btn btn-success" value="审核通过" th:onclick="setAuditStatus(11)">
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <input type="submit" class="btn btn-success" value="驳回" th:onclick="setAuditStatus(15)">
                                    </div>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <input type="button" th:onclick="'javascript:history.go(-1);'" class="btn btn-danger"  value="返回" >
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <footer th:replace="common/comm :: footer "></footer>
</div>

</body>
<script th:inline="javascript">

    var startDate =new Date([[${#dates.format(train.startDate, 'yyyy-MM-dd')}]]);
    //格式化日，如果小于9，前面补0
    var day = ("0" + startDate.getDate()).slice(-2);
    //格式化月，如果小于9，前面补0
    var month = ("0" + (startDate.getMonth() + 1)).slice(-2);
    //拼装完整日期格式
    var today = startDate.getFullYear()+"-"+(month)+"-"+(day) ;

    var endDate =new Date([[${#dates.format(train.endDate, 'yyyy-MM-dd')}]]);
    //格式化日，如果小于9，前面补0
    var endDateDay = ("0" + endDate.getDate()).slice(-2);
    //格式化月，如果小于9，前面补0
    var endDateMonth = ("0" + (endDate.getMonth() + 1)).slice(-2);
    //拼装完整日期格式
    var endDateToday = endDate.getFullYear()+"-"+(endDateMonth)+"-"+(endDateDay) ;
    //完成赋值
    jQuery(function($){


        /*下载资料*/
        function downloadFile(id) {
            if (confirm("是否要下载培训资料？")) {
                window.location.href = "/sys/train/downloadFile?id=" + id;
            }
        }

        window.downloadFile = downloadFile;


        /**
         * 设置审核,驳回状态
         */
        function setAuditStatus(status) {
            $("#auditStatus").val(status);
        }

        window.setAuditStatus = setAuditStatus;

        /*删除培训资料*/
        function delFile(id) {
            if (confirm("确定要删除培训资料吗？")) {
                $.ajax({
                    type: "GET",
                    url: "/sys/train/delFile",
                    data: {id: id},
                    dataType: "json",
                    success: function (data) {
                        if (data.result == "true") {
                            alert("删除成功!");
                            $("#trainFile").show();
                            $("#trainShow").html('');
                        } else {
                            alert("删除失败!");
                        }
                    },
                    error: function (data) {
                        alert("异常!");
                    }
                });
            }
        }

        window.delFile = delFile;


        $("#startDate").val(today);
        $("#endDate").val(endDateToday);
    });
</script>
</html>


